﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：打印设置
 */
var selectedRow;
var acceptClick;

var bootstrap = function ($, learun) {
    "use strict";
    var companyId = request("companyId");
    var ztId = request("ztId");
    var selectColumns = learun.frameTab.currentIframe().selectColumns;

    var page = {
        init: function () {
            page.inittree();
            page.bind();
        },
        bind: function () {
            // 全选
            $('#select_all').on('click', function (e) {
                $('.lr-tree-node-cb').trigger('click');
            });

            // 全不选
            $('#select_none').on('click', function (e) {
                $('#itemTree').lrtreeSet('allNoCheck');
            });

            // 搜索
            $("#txt_keyword").keydown(function (event) {
                if (event.keyCode == 13) {
                    var keyword = $(this).val();
                    $('#itemTree').lrtreeSet('search', {keyword: keyword});
                }
            });
        },
        inittree: function () {
            if (companyId != "" && ztId != '') {
                $('#itemTree').lrtree({
                    url: config.base_server() + 'gzitems/dropdownlist2?companyId=' + companyId + '&ztId=' + ztId + '&access_token=' + config.getToken().access_token,
                    param: {},
                    nodeDbClick: page.treeNodeDbClick
                });

                setTimeout(function () {
                    var cols = selectColumns.split(",");
                    for (var i = 0; i < cols.length; i++) {
                        var $div = $('.lr-tree-root').find('div[title=' + cols[i] + ']');
                        $div.find('.lr-tree-node-cb').trigger('click');
                    }
                }, 200);
            }
        },

    };

    // 保存数据
    acceptClick = function (callBack) {
        var postData = {};
        postData.columns = $("#itemTree").lrtreeSet('getCheckNodeIds').toString();

        if (!postData.columns) {
            learun.alert.warning('请选择工资款项！');
            return false;
        }
        return postData;
    };

    page.init();
}


